/* eslint-disable @typescript-eslint/no-explicit-any */
import myAxios from '@/requests'

// 注册
export const userRegister = async (data: any) => {
    return await myAxios.post('/api/register', data)
}

// 登录
export const userLogin = async (data: any) => {
    return await myAxios.post('/api/login', data)
}

// 获取当前用户信息
export const getCurrentUser = async () => {
    return await myAxios.get('/serv/userinfo/get')
}

// 更新头像
export const updateAvatar = async (file: File) => {
    // 创建FormData对象包装文件
    const formData = new FormData()
    // 注意：键名'avatar'必须与后端upload.single('avatar')保持一致
    formData.append('avatar', file)
    // 发送上传请求
    return await myAxios.post('/serv/userinfo/avatar', formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        },
    })
}

// 更新当前用户昵称
export const updateNickname = async (data: any) => {
    return await myAxios.post('/serv/userinfo/nickname', data)
}

// 更新密码
export const updatePassword = async (data: any) => {
    return await myAxios.post('/serv/userinfo/password', data)
}

// 根据信息查询用户
export const searchUsers = async (data: any) => {
    return await myAxios.post('/serv/userinfo/search', data)
}

// 根据uid获取用户基本信息
export const getUsersInfoByUID = async (data: any) => {
    return await myAxios.post('/serv/userinfo/uid', data)
}